home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.5
- date 89.01.13.11.44.28; author douglis; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 89.01.02.13.42.33; author douglis; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.09.22.22.12.04; author douglis; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.09.13.16.49.06; author douglis; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.08.14.15.08.37; author douglis; state Exp;
- branches ;
- next ;
-
-
- desc
- @Procedure to write a record into a database.
- @
-
-
- 1.5
- log
- @changed for buffering and for new arg passing to lock routine.
- [generic checkin msg].
- @
- text
- @/*
- * Db_Put.c --
- *
- * Source code for the Db_Put procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/db/RCS/Db_Put.c,v 1.4 89/01/02 13:42:33 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- #endif not lint
-
-
- #include <db.h>
- #include "dbInt.h"
-
-
- /*
- *----------------------------------------------------------------------
- *
- * Db_Put --
- *
- * Write a random entry, or the next entry in order, given the handle
- * for a database.
- *
- * Results:
- * -1 indicates an error, in which case errno indicates more details.
- * 0 indicates success.
- *
- * Side effects:
- * The position in the file is updated, and data are written to the file.
- *
- *----------------------------------------------------------------------
- */
-
- int
- Db_Put(handlePtr, bufPtr, index)
- Db_Handle *handlePtr;
- char *bufPtr;
- int index; /* -1 to indicate next in order */
- {
- register int streamID;
- int bufSize;
- int offset;
- int bytesWritten;
- int status;
-
- streamID = handlePtr->streamID;
- bufSize = handlePtr->structSize;
- if (handlePtr->lockWhen == DB_LOCK_ACCESS) {
- status = DbLockDesc(handlePtr);
- if (status == -1) {
- return(status);
- }
- }
- if (index == -1) {
- index = handlePtr->index;
- } else {
- offset = index * bufSize;
- status = lseek(streamID, (long) offset, L_SET);
- if (status == -1) {
- return(status);
- }
- }
- bytesWritten = write(streamID, bufPtr, bufSize);
- if (bytesWritten == -1) {
- status = -1;
- } else if (bytesWritten != bufSize) {
- status = -1;
- errno = 0;
- } else {
- status = 0;
- }
- handlePtr->index = index + 1;
- if (handlePtr->lockWhen == DB_LOCK_ACCESS ||
- handlePtr->lockWhen == DB_LOCK_READ_MOD_WRITE) {
- (void) flock(streamID, LOCK_EX | LOCK_UN);
- }
- return(status);
- }
- @
-
-
- 1.4
- log
- @added a lock type DB_LOCK_READ_MOD_WRITE.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/db/RCS/Db_Put.c,v 1.3 88/09/22 22:12:04 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- d58 1
- a58 2
- status = DbLockDesc(streamID, handlePtr->lockType,
- handlePtr->lockHow);
- @
-
-
- 1.3
- log
- @Changed some arg. orders, var. names, and Db_LockDesc to DbLockDesc.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Db_Put.c,v 1.2 88/09/13 16:49:06 douglis Exp $ SPRITE (Berkeley)";
- d83 2
- a84 1
- if (handlePtr->lockWhen == DB_LOCK_ACCESS) {
- @
-
-
- 1.2
- log
- @fixed some lint.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Db_Put.c,v 1.1 88/08/14 15:08:37 douglis Exp $ SPRITE (Berkeley)";
- d58 1
- a58 1
- status = Db_LockDesc(streamID, handlePtr->lockType,
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- d68 1
- a68 1
- status = lseek(streamID, offset, L_SET);
- @
-